package games.mapacman.common;

import games.mapacman.client.GameScreen;
import games.mapacman.server.MaPacmanZone;
import marauroa.common.game.RPClass;
import marauroa.common.game.RPObject;
import marauroa.common.game.Definition.Type;
import marauroa.server.game.Statistics;

public class Superdot extends Dot {

	private int superprob = 1;
	private int superdot_score;
	private boolean isSuperdot;

	public Superdot(int x, int y, int dot_score, int superdot_score,
			int superdot_probability, MaPacmanZone zone) {
		super(x, y, dot_score, zone);
		myObject.put("type", Constants.TYPE_SUPERDOT);
		myObject.put("superprob", superdot_probability);
		myObject.put("score", superdot_score);
		myObject.put("dottype", TYPE_SUPERDOT);
		superprob = superdot_probability;
		this.superdot_score = superdot_score;
		isSuperdot = true;
	}

	public Superdot(RPObject object) {
		super(object);
		isSuperdot = (myObject.getInt("dottype") == TYPE_SUPERDOT);
	}

	public static void initRPClass() {
		RPClass superdot = new RPClass(Constants.TYPE_SUPERDOT);
		superdot.isA(Constants.TYPE_DOT);
		superdot.addAttribute("dottype", Type.INT);
		superdot.addAttribute("superprob", Type.INT);
	}

	@Override
	public void setRespawnTime() {
		if (zone.getRandom().nextInt(superprob) == 0) { // Superdot
			myObject.put("score", superdot_score);
			myObject.put("dottype", TYPE_SUPERDOT);
			setRespawnTime(zone.getSuperDotRespawnTime());
		} else {
			myObject.put("dottype", TYPE_DOT);
			myObject.put("score", dot_score);
			setRespawnTime(zone.getDotRespawnTime());
		}
	}

	@Override
	public void addStats(Statistics stats) {
		if (myObject.getInt("dottype") == TYPE_SUPERDOT) {
			stats.add("Superdots eaten", 1);
		} else {
			super.addStats(stats);
		}
	}

	@Override
	public void draw(GameScreen screen) {
		if (isSuperdot) {
			screen.draw(screen.getDotSprite(TYPE_SUPERDOT), x, y);
		} else {
			screen.draw(screen.getDotSprite(TYPE_DOT), x, y);
		}
	}

}
